event_comment=
{
    commentLoading: false,
    commentPosting: false,
    commentPage: 0,
    firstTime: true,
    insertSymbol: function(symbol)
    {
        var obj=$('#comment_content').get(0);
        if (document.selection)
        {
            obj.focus();
            sel = document.selection.createRange();
            sel.text = symbol;
        }
        else if (obj.selectionStart || obj.selectionStart == 0)
        {
            var startPos = obj.selectionStart;
            var endPos = obj.selectionEnd;
            obj.value = obj.value.substring(0, startPos)
                        + symbol
                        + obj.value.substring(endPos, obj.value.length);
        } 
        else
        {
            obj.value += symbol;
        }
    },
    loadComment:  function(eid, p)
     {
         if (this.commentLoading)
         {
             return false;
         }
         $.ajax({
               type: "GET",
               url: "/event/comment/view/" + eid + "?p=cover&page=" + p,
               beforeSend: function(req){
                   $("#cmt_loader").show();
                   event_comment.commentLoading=true;
               },
               complete: function(res, s){
                   $("#comment_area").html(res.responseText);
                   $("#cmt_loader").hide();
                   event_comment.commentLoading=false;
                   event_comment.commentPage=p;
                   if (!event_comment.firstTime)
                   {
                        location.href='#comment_section';
                   }
                   else
                   {
                        event_comment.firstTime=false;
                   }
                   
                }       
            });
         return false;
     },
     deleteComment: function(cid)
     {
         if (!confirm("Bạn chắc chắn xóa bình luận này"))
             return false;
         $.ajax({
               type: "POST",
               url: "/event/comment/delete/" + cid + "?p=cover&page=" + this.commentPage,
               error: function(req, status, info){
                      alert("Có lỗi khi xóa bình luận. Hãy thử lại lần khác");
               },
               success: function(comment, status){
                      $("#comment_area").html(comment);
                      location.href='#comment_section';
               }
        });
        return false;
     },
    saveComment: function(eid, cid)
    {
        if (cid == '') {
            textAreaID = "#comment_content";
        } else {            
            textAreaID = "#comment_content_" + cid;
        }
        if ($(textAreaID).val()=="")
            return;
        if (event_comment.commentPosting)
            return;                        
        $.ajax({
               type: "POST",
               url: "/event/comment/save/" + eid + "/" + cid+"?p=cover",
               data: $(textAreaID).serialize(),
               beforeSend: function(req){
                   $("#cmt_loader").show();
                   event_comment.commentPosting=true;
               },
               error: function(req, status, info){
                      alert("Có lỗi khi cập nhật bình luận của bạn");
               },
               success: function(comment, status){
                      $("#comment_area").html(comment);
                      $(textAreaID).val("");
               },
               complete: function(res, s){
                   $("#cmt_loader").hide();
                   event_comment.commentPosting=false;
                   event_comment.commentPage=0;
                   location.href='#comment_section';
                }
        });
        return false;
    },
    showReplyBox: function(cid)
    {
        $("#reply_hint_" + cid).hide();
        $("#reply_box_" + cid).show();
        return false;
    },
    showReply: function(cid)
    {
        $('.reply_comment_' + cid).show();
        $('#display_reply_' + cid).hide();
        return false;
    }
}